﻿using System;
using System.Collections.Generic;
using System.Text;
using Manager.App_Code.IDAL;
using Manager.App_Code.DTO;
using System.Data;

namespace Manager.App_Code.DAL
{
    class ChiTietPhieuDangKyDAL:StandardConnectDB,IChiTietPhieuDangKy
    {
        public List<DTO.ChiTietPhieuDangKyPhongDTO> GetListPhieuDK()
        {
            throw new NotImplementedException();
        }

        public List<DTO.ChiTietPhieuDangKyPhongDTO> GetAllPhongByMaTang(int Matang)
        {
            throw new NotImplementedException();
        }



        public List<DTO.ChiTietPhieuDangKyPhongDTO> GetAllPhieuDKByMaPhieu(long Maphieu)
        {
            List<ChiTietPhieuDangKyPhongDTO> chitietphieudk = new List<ChiTietPhieuDangKyPhongDTO>();

            Dictionary<string, object> paramlist = new Dictionary<string, object>();

            paramlist.Add("@MaPhieuDangKy", Maphieu);

            DataTable dt = this.DTExecuteSelect("SP_ChiTietPhieuDangKy_GetByID", paramlist);

           
            foreach (DataRow dr in dt.Rows)
            {
                chitietphieudk.Add(ConvertObjectDataRowToChiTietPhieuDangKyPhongDTO(dr));
            }

            return chitietphieudk;

           
        }



        public bool InsertPhieuDK(DTO.ChiTietPhieuDangKyPhongDTO chitietphieudk)
        {
            Dictionary<string, object> paramlist = new Dictionary<string, object>();

            paramlist.Add("@MaPhieuDangKy", chitietphieudk.MaPhieuDangKy.MaPhieu);
            paramlist.Add("@MaPhong", chitietphieudk.MaPhong.MaPhong);
            paramlist.Add("@MaKhachHang", chitietphieudk.MaKhachHang.MaKH);
            paramlist.Add("@NgayDen", chitietphieudk.NgayDen);
            paramlist.Add("@NgayDi", chitietphieudk.NgayDi);

            return this.ExecuteUpdate("SP_ChiTietPhieuDangKy_Insert", paramlist);
 

        }

        public bool UpdatePhieuDK(DTO.ChiTietPhieuDangKyPhongDTO chitietphieudk)
        {
            throw new NotImplementedException();
        }

        public bool DeletePhieuDK(DTO.PhieuDangKyPhongDTO chitietphieudk)
        {
            throw new NotImplementedException();
        }

        public DTO.ChiTietPhieuDangKyPhongDTO ConvertObjectDataRowToChiTietPhieuDangKyPhongDTO(System.Data.DataRow dr)
        {

            if (dr != null)
            {
                ChiTietPhieuDangKyPhongDTO phieudk = new ChiTietPhieuDangKyPhongDTO();

                IPhieuDangKy iphieudk = new PhieuDangKyDAL();
                IPhong iphong = new PhongDAL();
                IKhachHang ikhach = new KhachHangDAL();
                
                phieudk.MaPhieuDangKy = iphieudk.GetPhieuDangKyPhongByMaPhieu(long.Parse(dr["MaPhieuDangKy"].ToString()));

                phieudk.MaPhong = iphong.GetPhongByID(dr["MaPhong"].ToString());

                phieudk.MaKhachHang = ikhach.GetKhachHangByID(dr["MaKhachHang"].ToString());

                phieudk.NgayDen = DateTime.Parse(dr["NgayDen"].ToString());

                phieudk.NgayDi = DateTime.Parse(dr["NgayDi"].ToString());

                return phieudk;
            }
            else
                return null;
        }


    }
}
